package com.sgb.jicai.entity;

import android.text.TextUtils;

import androidx.annotation.StyleableRes;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class FactoryCentralizedItemEntity implements Serializable {

    //省name
    @SerializedName(value = "saleProvinceName", alternate = {"provinceName"})
    private String saleProvinceName;
    //市name
    @SerializedName(value = "saleCityName", alternate = {"cityName"})
    private String saleCityName;
    //区名称
    @SerializedName(value = "saleDistrictName", alternate = {"districtName"})
    private String saleDistrictName;
    //公司名字
    @SerializedName(value = "createCompany", alternate = {"companyName"})
    private String createCompany;
    //商品名称
    @SerializedName("goodsName")
    private String goodsName;
    //no
    @SerializedName("no")
    private String no;
    //状态：1，集采中，2完成
    @SerializedName("status")
    private int status;
    //单位
    private String unitName;
    //二级物料列表
//    @SerializedName(value = "productSaleSlipDetails", alternate = {"details"})
    @SerializedName(value = "productSaleSlipDetails")
    private ArrayList<ProductSaleSlipDetails> productSaleSlipDetails;
    @SerializedName("details")//ES传值问题
    private String details;
    //跳转企业店铺id
    @SerializedName(value = "supplierId", alternate = {"companyId"})
    private String supplierId;
    private String companyNo;
    @SerializedName("customerServiceContactsId")
    private String customerServiceContactsId;
    @SerializedName("contactNumber")
    private String contactNumber;
    @SerializedName("contacts")
    private String contacts;
    @SerializedName("joinNum")
    private String joinNum;

    public String getJoinNum() {
        return joinNum;
    }

    public void setJoinNum(String joinNum) {
        this.joinNum = joinNum;
    }

    /**
     * 价格预警 1 大于 2 等于 3 小于
     */
    private int priceWarning;

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public ArrayList<ProductSaleSlipDetails> getProductSaleSlipDetails() {
        return getProductSaleSlipDetailsList(getDetails());
    }

    public void setProductSaleSlipDetails() {
        this.productSaleSlipDetails = getProductSaleSlipDetailsList(getDetails());
    }

    public String getCreateCompany() {
        return createCompany;
    }

    public void setCreateCompany(String createCompany) {
        this.createCompany = createCompany;
    }

    public String getSaleCityName() {
        return saleCityName;
    }

    public void setSaleCityName(String saleCityName) {
        this.saleCityName = saleCityName;
    }

    public String getCustomerServiceContactsId() {
        return customerServiceContactsId;
    }

    public void setCustomerServiceContactsId(String customerServiceContactsId) {
        this.customerServiceContactsId = customerServiceContactsId;
    }

    public String getSaleDistrictName() {
        return saleDistrictName;
    }

    public void setSaleDistrictName(String saleDistrictName) {
        this.saleDistrictName = saleDistrictName;
    }

    public String getSaleProvinceName() {
        return saleProvinceName;
    }

    public void setSaleProvinceName(String saleProvinceName) {
        this.saleProvinceName = saleProvinceName;
    }

    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getContacts() {
        return contacts;
    }

    public void setContacts(String contacts) {
        this.contacts = contacts;
    }

    public String getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(String supplierId) {
        this.supplierId = supplierId;
    }

    public String getCompanyNo() {
        return companyNo;
    }

    public void setCompanyNo(String companyNo) {
        this.companyNo = companyNo;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getPriceWarning() {
        return priceWarning;
    }

    public void setPriceWarning(int priceWarning) {
        this.priceWarning = priceWarning;
    }

    public String getUnitName() {
        if (null != unitName && !unitName.isEmpty()) {
            return "集采价（元/" + unitName + ")";
        } else {
            return "集采价";
        }
    }

    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    public class ProductSaleSlipDetails {
        //最高价
        private String maxPrice;
        //最低价
        private String minPrice;
        //购买数量
        private String num;
        //单位名称
        private String unitName;
        private List<AttrsEntity> attrs;
        private String salePricingRules;
        private String countNum;

        public String getMaxPrice() {
            return maxPrice;
        }

        public void setMaxPrice(String maxPrice) {
            this.maxPrice = maxPrice;
        }

        public String getMinPrice() {
            return minPrice;
        }

        public void setMinPrice(String minPrice) {
            this.minPrice = minPrice;
        }

        public String getNum() {
            return num;
        }

        public void setNum(String num) {
            this.num = num;
        }

        public String getUnitName() {
            return unitName;
        }

        public void setUnitName(String unitName) {
            this.unitName = unitName;
        }

        public String getSalePricingRules() {
            if (minPrice.equals(maxPrice)){
                return maxPrice;
            }else {
                return minPrice + "~" + maxPrice;
            }
        }

        public void setSalePricingRules(String salePricingRules) {
            this.salePricingRules = salePricingRules;
        }

        public void setAttrs(List<AttrsEntity> attrs) {
            this.attrs = attrs;
        }

        public String getAttrs() {
            if (null == attrs || attrs.size() == 0) {
                return "无";
            }
            StringBuffer str = new StringBuffer();
            for (int i = 0; i < attrs.size(); i++) {
                str.append(attrs.get(i).getName()).append(":").append(attrs.get(i).getValue()).append("  ");
            }
            return TextUtils.isEmpty(new String(str)) ? "无" : new String(str);
        }

        public String getCountNum() {
            return TextUtils.isEmpty(countNum) ? "无" : countNum;
        }

        public void setCountNum(String countNum) {
            this.countNum = countNum;
        }
    }

    public class AttrsEntity {
        private String name;
        private String value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    private ArrayList<ProductSaleSlipDetails> getProductSaleSlipDetailsList(String jsonData) {
        Gson gson = new Gson();
        Type detailsType = new TypeToken<ArrayList<ProductSaleSlipDetails>>() {
        }.getType();
        ArrayList<ProductSaleSlipDetails> slipDetailsEntity = gson.fromJson(jsonData, detailsType);
        return slipDetailsEntity;
    }

}
